package environment.dungeons;

import static org.junit.Assert.*;
import org.junit.*;

import java.math.BigDecimal;
import java.math.BigInteger;

import temperature.Temperature;
import temperature.TemperatureUnit;

import environment.Direction;
import environment.Position;
import environment.borders.Door;

public class ShaftTest {

	Shaft<NormalSquare> shaft;
	NormalSquare square1;
	NormalSquare square2;
	NormalSquare square3;
	NormalSquare square4;
	NormalSquare square5;
	
	@BeforeClass
	public static void setUpBeforeClass() throws Exception {
	}

	@AfterClass
	public static void tearDownAfterClass() throws Exception {
	}

	@Before
	public void setUp() throws Exception {
		shaft = new Shaft<NormalSquare>(Direction.CEILING);
		square1 = new NormalSquare(new Temperature(new BigDecimal(BigInteger.valueOf(200),1), 
				TemperatureUnit.CELSIUS), new BigDecimal(BigInteger.valueOf(000),2), Direction.NORTH,Direction.SOUTH);
		square2 = new NormalSquare(new Temperature(new BigDecimal(BigInteger.valueOf(500),1), 
				TemperatureUnit.CELSIUS), new BigDecimal(BigInteger.valueOf(3000),2),Direction.EAST , Direction.WEST);
		square3 = new NormalSquare(new Temperature(new BigDecimal(BigInteger.valueOf(1000),1), 
				TemperatureUnit.CELSIUS), new BigDecimal(BigInteger.valueOf(6000),2));
		square4 = new NormalSquare();
		square4.buildNewBorderIn(new Door(false), Direction.NORTH);
		square4.breakBorderDownIn(Direction.FLOOR);
		square4.buildNewBorderIn(new Door(false), Direction.CEILING);
		square5 = new NormalSquare();
		square5.buildNewBorderIn(new Door(false), Direction.WEST);
	}

	@After
	public void tearDown() throws Exception {
	}
	
	@Test
	public void testConstruction(){
		assertEquals(shaft.getMaximumX(),0);
		assertEquals(shaft.getMaximumY(),0);
		assertEquals(shaft.getMaximumZ(),10);
		assertEquals(shaft.getDirectionOfShaft(), Direction.CEILING);
	}
	
	@Test 
	public void testAlterDimensions(){
		shaft.setDimensionLimits(shaft.getMaximumX(),shaft.getMaximumY(),60);
		try{
			shaft.setDimensionLimits(1,shaft.getMaximumY(),shaft.getMaximumZ());
			assert false;
		}catch (IllegalArgumentException ie) {
			assert true;
		}
		try{
			shaft.setDimensionLimits(shaft.getMaximumX(),1,shaft.getMaximumZ());
			assert false;
		}catch (IllegalArgumentException ie) {
			assert true;
		}
	}

	@Test
	public void testPuttingSquaresOnPositions(){
		assertEquals(shaft.getDirectionOfShaft(), Direction.CEILING);
		Position position1 = new Position(0, 0, 2);
		Position position2 = new Position(0, 0, 10);
		Position position3 = new Position(0, 0, 50);
		shaft.addSquareAt(square1, position1);
		shaft.addSquareAt(square2, position2);
		try{
			shaft.addSquareAt(square3, position3);
			assert false;
		}catch (IllegalArgumentException ie) {
			assert true;
		}
		shaft.setDimensionLimits(shaft.getMaximumX(), shaft.getMaximumY(), 50);
		shaft.addSquareAt(square3, position3);
	}
	
	@Test
	public void testClosedBorderBetweenSquares(){
		shaft.addSquareAt(square1, new Position(0, 0, 3));
		shaft.addSquareAt(square2, new Position(0, 0, 4));
		shaft.addSquareAt(square3, new Position(0, 0, 2));
		shaft.removeAsSquare(square3);
		try {
			shaft.addSquareAt(square3, new Position(0, 0, 5));
			assert false;
		} catch (IllegalArgumentException e) {
			assert true;
		}
		try {
			shaft.addSquareAt(square4, new Position(0, 0, 2));
			assert false;
		} catch (IllegalArgumentException e) {
			assert true;
		}
		shaft.addSquareAt(square4, new Position(0, 0, 5));
		try {
			shaft.addSquareAt(square3, new Position(0, 0, 6));
			assert false;
		} catch (IllegalArgumentException e) {
			assert true;
		}
		
	}

}
